import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/manager/xindong_user_controller.dart';
import 'package:xindong/routes/user/income/xindong_income_list_container.dart';
import 'package:xindong/routes/user/income/xindong_income_vm.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/common/xindong_tab_indicator.dart';

class XinDongIncomeListYeMian extends StatefulWidget {
  const XinDongIncomeListYeMian({super.key});

  @override
  State<XinDongIncomeListYeMian> createState() => _XinDongIncomeListYeMianState();
}

class _XinDongIncomeListYeMianState extends State<XinDongIncomeListYeMian> {
  final tabBars = const [Tab(text: "收入"), Tab(text: "支出")];
  final String kControllerTagIn = "kControllerTagIn";
  final String kControllerTagOut = "kControllerTagOut";
  final visitMeVM = XinDongIncomeVM(type: IncomeType.shouru);
  final mineVisitVM = XinDongIncomeVM(type: IncomeType.zhichu);

  // TabView
  List<Widget> tabBarViews() {
    return [
      XinDongIncomeListContainer(
        controllerTag: kControllerTagIn,
        emptyTips: '还没有收入哦',
      ),
      XinDongIncomeListContainer(
        controllerTag: kControllerTagOut,
        emptyTips: '还没有支出哦',
      ),
    ];
  }

  @override
  void initState() {
    super.initState();

    // tag标记同一个控制器名称，区分不同实例
    Get.create(() => visitMeVM, tag: kControllerTagIn, permanent: false);
    Get.create(() => mineVisitVM, tag: kControllerTagOut, permanent: false);

    XinDongUserController.to.requestUserScore();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: XinDongAppBar("清单"),
      body: DefaultTabController(
        length: tabBars.length,
        child: Column(
          children: [
            Container(
              height: 44.0,
              alignment: Alignment.center,
              child: TabBar(
                indicator: const XinDongTabIndicator(color: DZColors.mainColor),
                indicatorSize: TabBarIndicatorSize.label,
                labelPadding: const EdgeInsets.only(left: 16, right: 5),
                labelColor: DZColors.titleColor,
                unselectedLabelColor: DZColors.contentColor,
                labelStyle: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
                unselectedLabelStyle: const TextStyle(fontSize: 16),
                tabs: tabBars,
              ),
            ),
            Expanded(
              child: TabBarView(children: tabBarViews()),
            ),
          ],
        ),
      ),
    );
  }
}
